package com.jeez.module.sys.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import com.jeez.common.entity.DataEntity;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.List;

/**
 * @author: Felix
 * @date: 2018-7-1
 * @version: v1.0
 * @description:
 */
@Entity
@Table(name = "t_sys_menu")
@Getter
@Setter
public class SysMenu extends DataEntity<SysMenu> {


    /**
     * 菜单名
     */
    @Column(name = "menu_name", nullable = false, insertable = true, updatable = true, length = 200)
    private String menuName;

    /**
     * 上级菜单ID（根菜单为0）
     */
    @Column(name = "parent_id", nullable = false, insertable = true, updatable = true)
    private long parentId;

    /**
     * 菜单类型
     */
    @Column(name = "menu_type", nullable = true, insertable = true, updatable = true, length = 20)
    private String menuType;

    /**
     * 菜单地址
     */
    @Column(name = "menu_url", nullable = true, insertable = true, updatable = true, length = 300)
    private String menuUrl;

    /**
     * 菜单打开目标（mainFrame、_blank、_self、_parent、_top）
     */
    @Column(name = "target", nullable = true, insertable = true, updatable = true, length = 20)
    private String target;

    /**
     * 图标
     */
    @Column(name = "icon", nullable = true, insertable = true, updatable = true, length = 60)
    private String icon;

    /**
     * 权限串
     */
    @Column(name = "permission_value", nullable = true, insertable = true, updatable = true, length = 500)
    private String permissionValue;

    /**
     * 所有菜单号
     */
    @Column(name = "menu_seq", nullable = true, insertable = true, updatable = true, length = 300)
    private String menuSeq;

    /**
     * 排序ID
     */
    @Column(name = "order_num", nullable = false, insertable = true, updatable = true)
    private long orderNum;

    /**
     * 是否显示
     */
    @Column(name = "is_show", length = 1)
    private boolean show;

    /**
     * 状态
     */
    @Column(name = "status", nullable = false, insertable = true, updatable = true, length = 4)
    private String status;

    /**
     * 模块ID
     */
    @Column(name = "system_id", nullable = true, insertable = true, updatable = true)
    private Long systemId;


    /**
     * 备注
     */
    @Column(name = "remark", nullable = true, insertable = true, updatable = true, length = 400)
    private String remark;

    /**
     * @JoinTable描述了多对多关系的数据表关系。name属性指定中间表名称,joinColumns定义中间表与User表的外键关系
     *
     */
    @ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
    @JoinTable(name = "t_sys_role_menu",
               joinColumns = {@JoinColumn(name = "menu_id")},
               inverseJoinColumns = {@JoinColumn(name = "role_id")} )
    @JsonIgnore
    private List<SysRole> roles = Lists.newArrayList();

}
